package shiyan1;

public class MaxSubarraySum {
    public static void main(String[] args) {
        int[] nums = {1, -2, 3, 5, -1};
        int maxSum = Integer.MIN_VALUE;
        int currentSum = 0;

        for (int num : nums) {
            currentSum = Math.max(num, currentSum + num);
            maxSum = Math.max(maxSum, currentSum);
        }

        System.out.println(maxSum);
    }
}